using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace TimeWar
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class PlayDemoScreen : Screen
    {
        protected Camera gameCamera = null;
        protected Dalek dalek = null;
        protected Game gameObj = null;
        protected Starship enterprise_E = null;
        protected Starship XWingFighter = null;
        protected Starship MilleniumFalcon = null;
        protected Starship Tardis = null;

        public PlayDemoScreen(Game game)
            : base(game)
        {
            float aspectRatio = 16 / 9;
            float fov = 3.14f / 2;
            gameCamera = new Camera(fov, 10f, 700f) ;

            // TODO: Construct any child components here
            gameObj = game;
            //dalek = new Dalek(gameObj);
            enterprise_E = new Starship(game, "Content\\Models\\StarTrek\\Federation\\Starships\\SovereignBc");
            //XWingFighter = new Starship(game, "Content\\Models\\XWing");
            //MilleniumFalcon = new Starship(game, "Content\\Models\\MilleniumFalcon");

            enterprise_E.Position3D = new Vector3(200, 100, 0);

            //Tardis = new Starship(game, "Content\\Models\\DrWho\\TimeLord\\Starships\\TARDIS");
            //Tardis.Position = new Vector3(400, 200, 20);

        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// 
        public override GameState Update(TimeSpan time, TimeSpan elapsedTime)
        {
            //dalek.Update(time, elapsedTime);
            enterprise_E.Update(time, elapsedTime);
            //XWingFighter.Update(time, elapsedTime);
            //MilleniumFalcon.Update(time, elapsedTime);
            gameCamera.Update();

            enterprise_E.Camera = gameCamera.ViewPosition;
            enterprise_E.View = gameCamera.View;

            return base.Update(time, elapsedTime);
        }

        public override void Render()
        {
            IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)GameInstance.Services.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice device = graphicsService.GraphicsDevice;

            //Sprites will always be at the back.
            device.RenderState.DepthBufferWriteEnable = false;
            device.Clear(Color.Black);

            //SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);

            //dalek.Draw();
            enterprise_E.Render();
            //XWingFighter.Render();
            //MilleniumFalcon.Render();

            //SpriteBatch.End();

            //Tardis.Render();

            base.Render();
        }

    }
}